import React, {PureComponent} from 'react';

// PureComponent替代了shouldComponentUpdate中的新老state手动判断 阻止了state不变情况下的重复渲染
class App extends PureComponent {
    state = {
        name: '张三'
    }
    render() {
        return (<div>
            <button onClick={() => this.setState({name: '李四'})}>click</button>
            {this.state.name}
        </div>);
    }

    // shouldComponentUpdate(nextProps, nextState, nextContext) {
    //     // state内容不改变就不重新渲染dom
    //     return JSON.stringify(this.state) !== JSON.stringify(nextState);
    // }

    UNSAFE_componentWillUpdate(nextProps, nextState, nextContext) {
        console.log("UNSAFE_componentWillUpdate")
    }

    componentDidUpdate(prevProps, prevState, snapshot) {
        console.log("componentDidUpdate");
    }
}

export default App;